package com.zj.fx.controller.month;

import com.zj.fx.common.base.BaseController;
import com.zj.fx.common.domain.AjaxResult;
import com.zj.fx.common.domain.ResultTable;
import com.zj.fx.model.custom.Tablepar;
import com.github.pagehelper.PageInfo;
import com.zj.fx.model.month.MonthAuditSub;
import com.zj.fx.model.month.MonthConstant;
import com.zj.fx.model.month.MonthSupplytask;
import com.zj.fx.service.month.MonthAuditSubService;
import com.zj.fx.service.month.MonthSupplytaskService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

/**
 * 月度分公司审核提交明细Controller
 * @ClassName: MonthAuditSubController
 * @author SQL
 * @date 2023-07-13 10:26:26
 */
@Api(value = "月度分公司审核提交明细")
@Controller
@RequestMapping("/MonthAuditSubController")
public class MonthAuditSubController extends BaseController {

    private String prefix = "month/monthAuditSub";

    @Autowired
    private MonthAuditSubService monthAuditSubService;

    @Autowired
    private MonthSupplytaskService monthSupplytaskService;


    /**
     * 月度分公司审核提交明细页面展示
     * @param model
     * @return String
     * @author SQL
     */
    @ApiOperation(value = "分页跳转", notes = "分页跳转")
    @GetMapping("/view")
    @RequiresPermissions("gen:monthAuditSub:view")
    public String view(ModelMap model) {
        return prefix + "/list";
    }

    /**
     * list集合
     * @param tablepar
     * @param
     * @return
     */
    //@Log(title = "月度分公司审核提交明细", action = "111")
    @ApiOperation(value = "分页跳转", notes = "分页跳转")
    @GetMapping("/list")
    @RequiresPermissions("gen:monthAuditSub:list")
    @ResponseBody
    public ResultTable list(Tablepar tablepar, MonthAuditSub monthAuditSub) {
        PageInfo<MonthAuditSub> page = monthAuditSubService.list(tablepar,monthAuditSub);
        return pageTable(page.getList(), page.getTotal());
    }

    /**
     * 新增跳转
     */
    @ApiOperation(value = "新增跳转", notes = "新增跳转")
    @GetMapping("/add")
    public String add(ModelMap modelMap) {
        return prefix + "/add";
    }

    /**
     * 新增保存
     * @param 
     * @return
     */
    //@Log(title = "月度分公司审核提交明细新增", action = "111")
    @ApiOperation(value = "新增", notes = "新增")
    @PostMapping("/add")
    @RequiresPermissions("gen:monthAuditSub:add")
    @ResponseBody
    public AjaxResult add(MonthAuditSub monthAuditSub) {
        int b = monthAuditSubService.insertSelective(monthAuditSub);
        if (b > 0) {
            return success();
        } else {
            return error();
        }
    }

    /**
     * 月度分公司审核提交明细删除
     * @param ids
     * @return
     */
    //@Log(title = "月度分公司审核提交明细删除", action = "111")
    @ApiOperation(value = "删除", notes = "删除")
    @DeleteMapping("/remove")
    @RequiresPermissions("gen:monthAuditSub:remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        int b = monthAuditSubService.deleteByPrimaryKey(ids);
        if (b > 0) {
            return success();
        } else {
            return error();
        }
    }


    /**
     * 修改跳转
     * @param id
     * @param
     * @return
     */
    @ApiOperation(value = "修改跳转", notes = "修改跳转")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap map) {
        map.put("MonthAuditSub", monthAuditSubService.selectByPrimaryKey(id));

        return prefix + "/edit";
    }

    /**
     * 修改保存
     */
    //@Log(title = "月度分公司审核提交明细修改", action = "111")
    @ApiOperation(value = "修改保存", notes = "修改保存")
    @RequiresPermissions("gen:monthAuditSub:edit")
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MonthAuditSub monthAuditSub) {
        return toAjax(monthAuditSubService.updateByPrimaryKeySelective(monthAuditSub));
    }

    /**
     * 查询月度分公司填报进度
     *
     * @param tablepar
     * @param
     * @return
     */
    @ApiOperation(value = "查询月度分公司填报进度", notes = "查询月度分公司填报进度")
    @GetMapping("/list4subcommitplan/{evaluationId}")
    @ResponseBody
    public ResultTable list4FillPlan(@PathVariable("evaluationId") String evaluationId,Tablepar tablepar, MonthAuditSub monthAuditSub) {

        PageInfo<MonthAuditSub> page = monthAuditSubService.list4subcommitplan(evaluationId,tablepar,monthAuditSub);
        return pageTable(page.getList(), page.getTotal());
    }

    /**
     * 查看完成进度中对应的供电所列表跳转
     * @param
     * @return
     */
    @ApiOperation(value = "查看完成进度中对应的供电所列表跳转", notes = "查看完成进度中对应的供电所列表跳转")
    @GetMapping("/supplyList/{evaluationId}/{fkSubcompanyId}/{state}")
    public String edit(@PathVariable("evaluationId") String evaluationId,@PathVariable("fkSubcompanyId") String fkSubcompanyId,@PathVariable("state") String state, ModelMap map) {
        map.put("evaluationId", evaluationId);
        map.put("fkSubcompanyId", fkSubcompanyId);
        map.put("state", state);
        if (MonthConstant.TASK_STATE_NOFILL.equals(state)){
            return prefix + "/notfinishlist";
        }else {
            return prefix + "/finishlist";
        }
    }
}
